package com.engine.kq.cmd.dutyrules;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType4Hrm;
import com.engine.common.constant.BizLogType;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQDutyRulesBiz;
import com.engine.kq.log.KQLog;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 加班规则--编辑
 */
public class EditDutyRulesCmd extends AbstractCommonCommand<Map<String, Object>> {

    private SimpleBizLogger logger;

    public EditDutyRulesCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
        this.logger = new SimpleBizLogger();

        int ruleId = Util.getIntValue((String) params.get("ruleId"), 0);
        BizLogContext bizLogContext = new BizLogContext();
        bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型
        bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_OVERTIMERULES);//所属大类型
        bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_OVERTIMERULES);//当前小类型
        bizLogContext.setParams(params);//当前request请求参数
        logger.setUser(user);//当前操作人
        String mainSql = "select * from kq_overtimeRules where id="+ruleId;
        logger.setMainSql(mainSql, "id");//主表sql
        logger.setMainPrimarykey("id");//主日志表唯一key
        logger.setMainTargetNameColumn("name");

        SimpleBizLogger.SubLogInfo subLogInfo = logger.getNewSubLogInfo();
        String subSql = "select * from kq_overtimeRulesDetail where ruleId="+ruleId +" order by id";
        subLogInfo.setSubSql(subSql, "id");
        logger.addSubLogInfo(subLogInfo);
        logger.before(bizLogContext);
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public List<BizLogContext> getLogContexts() {
        return logger.getBizLogContexts();
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            /*加班规则的ID*/
            int ruleId = Util.getIntValue((String) params.get("ruleId"), 0);
            if (ruleId == 0) {
                resultMap.put("status", "-1");
                resultMap.put("message", SystemEnv.getHtmlLabelName(388858, user.getLanguage()));
                return resultMap;
            }

            boolean canEdit = HrmUserVarify.checkUserRight("KQOvertimeRulesEdit:Edit", user);//是否具有编辑的权限;
            if (!canEdit) {
                resultMap.put("status", "-1");
                resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
                return resultMap;
            }

            /*加班规则名称*/
            String name = Util.null2String(params.get("name"));
            /*考勤组的ID*/
            String groupIds = Util.null2String(params.get("groupIds"));

            /*工作日是否允许加班：0-不允许、1-允许*/
            int overtimeEnable2 = Util.getIntValue((String) params.get("dutyEnable2"), 1);
            /*工作日的加班方式：1-需审批，以审批单为准、2-需审批，以打卡为准，但是不能超过审批时长、3-无需审批，根据打卡时间计算加班时长*/
            int computingMode2 = Util.getIntValue((String) params.get("computingMode2"), 1);
            /*工作日下班多少分钟后开始计算加班*/
            int startTime2 = Util.getIntValue((String) params.get("startTime2"), 30);
            /*工作日最小加班时长*/
            int minimumLen2 = Util.getIntValue((String) params.get("minimumLen2"), 30);
            /*工作日是否允许加班转调休*/
            int paidLeaveEnable2 = Util.getIntValue((String) params.get("paidLeaveEnable2"), 0);
            /*工作日加班转调休比例中的加班时长*/
            double lenOfDuty2 = Util.getDoubleValue((String) params.get("lenOfDuty2"), 30.0);
            /*工作日加班转调休比例中的调休时长*/
            double lenOfLeave2 = Util.getDoubleValue((String) params.get("lenOfLeave2"), 30.0);

            /*休息日是否允许加班：0-不允许、1-允许*/
            int overtimeEnable3 = Util.getIntValue((String) params.get("dutyEnable3"), 1);
            /*休息日的加班方式：1-需审批，以审批单为准、2-需审批，以打卡为准，但是不能超过审批时长、3-无需审批，根据打卡时间计算加班时长*/
            int computingMode3 = Util.getIntValue((String) params.get("computingMode3"), 1);
            /*休息日的最小加班时长*/
            int minimumLen3 = Util.getIntValue((String) params.get("minimumLen3"), 30);
            /*休息日是否允许加班转调休*/
            int paidLeaveEnable3 = Util.getIntValue((String) params.get("paidLeaveEnable3"), 0);
            /*休息日加班转调休比例中的加班时长*/
            double lenOfDuty3 = Util.getDoubleValue((String) params.get("lenOfDuty3"), 30.0);
            /*休息日加班转调休比例中的调休时长*/
            double lenOfLeave3 = Util.getDoubleValue((String) params.get("lenOfLeave3"), 30.0);
            /*休息日是否有休息时间*/
            int hasRestTime3 = Util.getIntValue((String) params.get("hasRestTime3"), 0);

            /*节假日是否允许加班：0-不允许、1-允许*/
            int overtimeEnable1 = Util.getIntValue((String) params.get("dutyEnable1"), 1);
            /*节假日的加班方式：1-需审批，以审批单为准、2-需审批，以打卡为准，但是不能超过审批时长、3-无需审批，根据打卡时间计算加班时长*/
            int computingMode1 = Util.getIntValue((String) params.get("computingMode1"), 1);
            /*节假日的最小加班时长*/
            int minimumLen1 = Util.getIntValue((String) params.get("minimumLen1"), 30);
            /*节假日是否允许加班转调休*/
            int paidLeaveEnable1 = Util.getIntValue((String) params.get("paidLeaveEnable1"), 0);
            /*节假日加班转调休比例中的加班时长*/
            double lenOfDuty1 = Util.getDoubleValue((String) params.get("lenOfDuty1"), 30.0);
            /*假节日加班转调休比例中的调休时长*/
            double lenOfLeave1 = Util.getDoubleValue((String) params.get("lenOfLeave1"), 30.0);
            /*节假日是否有休息时间*/
            int hasRestTime1 = Util.getIntValue((String) params.get("hasRestTime1"), 0);

          if(computingMode2 == 4 || computingMode1 == 4 || computingMode3 == 4 ){
            //如果是流程和打卡取交集的话，加班单位不能是下拉框半天或者整天
            int minimumUnit = KQDutyRulesBiz.getMinimumUnit();
            if(minimumUnit == 2 || minimumUnit == 4){
              resultMap.put("sign", "-1");
              resultMap.put("message", SystemEnv.getHtmlLabelName(529168, user.getLanguage()));
              return resultMap;
            }
          }
          KQLog kqLog = new KQLog();
          kqLog.info("EditOverTimeRulesCmd:params:"+params);


          /*获取今天的日期*/
          Calendar today = Calendar.getInstance();
          String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
              + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
              + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);
          String tomorrowDate = DateUtil.addDate(currentDate, 1);

          //顺序显示，2是工作日，3是休息日，1是节假日
          int[] changetype = {2,3,1};

          boolean flag = false;//是否保存成功

          String sql = "update kq_DutyRules set name=?,groupIds=? where id=?";
          RecordSet recordSet = new RecordSet();
          RecordSet recordSet1 = new RecordSet();
          RecordSet recordSet2 = new RecordSet();
          flag = recordSet.executeUpdate(sql, name, groupIds, ruleId);
          if (!flag) {
            resultMap.put("sign", "-1");
            resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
            return resultMap;
          }
          Map<String,String> detailMap = Maps.newHashMap();
          String detailSql = "select * from kq_DutyRulesDetail where ruleId=?";
          recordSet.executeQuery(detailSql,ruleId);
          while (recordSet.next()){
            String daytype = recordSet.getString("daytype");
            String id = recordSet.getString("id");
            detailMap.put(daytype, id);
          }

          String[] fields = new String[]{"dutyEnable","computingMode","startTime","minimumLen",
              "paidLeaveEnable","lenOfDuty","lenOfLeave","hasRestTime","before_startTime",
              "has_cut_point","cut_point","paidLeaveEnableType","paidLeaveEnableDefaultType",
              "paidLeaveEnableFlowType","restTimeType"};
          String str_fields = Arrays.asList(fields).stream().collect(Collectors.joining(","));
          String split_str = Arrays.asList(fields).stream().map(s -> {return "?";}).collect(Collectors.joining(","));
          for(int i = 0 ; i < changetype.length ; i++) {
            int changetype_index = changetype[i];
            String fieldName = "";
            for(int j = 0 ; j < fields.length ;j++){
              String _key = fields[j]+changetype_index;
              String _value = Util.null2String(params.get(_key));
              if("before_startTime".equalsIgnoreCase(fields[j])){
                _value = Util.null2s(Util.null2String(params.get(_key)),"0");
              }
              if("startTime".equalsIgnoreCase(fields[j])){
                _value = Util.null2s(Util.null2String(params.get(_key)),"0");
              }
              fieldName += ","+fields[j]+"='"+_value+"'";
            }
            if(fieldName.length() > 0){
              fieldName = fieldName.substring(1);
              fieldName += ",ruleId="+ruleId+",dayType="+changetype_index;
              String detailid = Util.null2s(detailMap.get((changetype_index+"")),"-1");

              String updateSql = "update kq_DutyRulesDetail set "+fieldName+" where id = ? ";
              flag = recordSet.executeUpdate(updateSql,detailid);
              if(flag){

                List<String> restIds = Lists.newArrayList();
                List<String> lengthDetailIds = Lists.newArrayList();
                List<String> timeDetailIds = Lists.newArrayList();
                int rulesdetailid = Util.getIntValue(detailid);

                String hasRestTime_key = "hasRestTime"+changetype_index;
                String hasRestTime_value = Util.null2String(params.get(hasRestTime_key));
                if("1".equalsIgnoreCase(hasRestTime_value)){
                  String restTimeType_key = "restTimeType"+changetype_index;
                  String restTimeType_value = Util.null2String(params.get(restTimeType_key));

                  String restTimeRule_key = "restTimeRule"+changetype_index;
                  String restTimeRule_value = Util.null2String(params.get(restTimeRule_key));
                  if(restTimeRule_value.length() > 0){
                    JSONArray jsonArray = JSONArray.parseArray(restTimeRule_value);
                    if("1".equalsIgnoreCase(restTimeType_value)){
                      String deleteSql = "delete from kq_DutyRestTime where dayType=? and ruleId = ?";
                      flag = recordSet.executeUpdate(deleteSql, changetype_index,ruleId);
                      if (!flag) {
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                      for(int k = 0 ; k < jsonArray.size() ; k++){
                        JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                        String startType = "0";
                        String endType = "0";
                        String startTime = Util.null2String(jsonObject.get("startTime"));
                        String endTime = Util.null2String(jsonObject.get("endTime"));
                        String restTimeSql = "insert into kq_DutyRestTime(ruleId,dayType,startType,startTime,endType,endTime) values(?,?,?,?,?,?)";
                        flag = recordSet.executeUpdate(restTimeSql, ruleId, changetype_index, startType, startTime, endType, endTime);
                        if (flag) {
                          int restDetailId = 0;
                          String getIdSql = "select max(id) maxId from kq_DutyRestTime";
                          recordSet1.executeQuery(getIdSql);
                          if (recordSet1.next()) {
                            restDetailId = recordSet1.getInt("maxId");
                            restIds.add(""+restDetailId);
                          }
                          resultMap.put("sign", "1");
                          resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                        } else {
                          if(!restIds.isEmpty()){
                            if(restIds != null && !restIds.isEmpty()){
                              for(String detailId : restIds){
                                String delSql = "delete from kq_DutyRestTime where id = ? ";
                                recordSet2.executeUpdate(delSql,detailId);
                              }
                            }
                          }
                          resultMap.put("sign", "-1");
                          resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                          return resultMap;
                        }
                      }
                    }else if("2".equalsIgnoreCase(restTimeType_value)){
                      String deleteSql = "delete from kq_DutyRestlength where dayType=? and ruleId = ?";
                      flag = recordSet.executeUpdate(deleteSql, changetype_index,ruleId);
                      if (!flag) {
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                      for(int k = 0 ; k < jsonArray.size() ; k++){
                        JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                        String overtime = Util.null2String(jsonObject.get("overtime"));
                        String exclude = Util.null2String(jsonObject.get("exclude"));
                        String restTimeSql = "insert into kq_DutyRestlength(ruleId,dayType,overlength,cutlength,dsporder) values(?,?,?,?,?)";
                        flag = recordSet.executeUpdate(restTimeSql, ruleId, changetype_index, overtime, exclude, k);
                        if (flag) {
                          int restDetailId = 0;
                          String getIdSql = "select max(id) maxId from kq_DutyRestlength";
                          recordSet1.executeQuery(getIdSql);
                          if (recordSet1.next()) {
                            restDetailId = recordSet1.getInt("maxId");
                            restIds.add(""+restDetailId);
                          }
                          resultMap.put("sign", "1");
                          resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                        } else {
                          if(!restIds.isEmpty()){
                            if(restIds != null && !restIds.isEmpty()){
                              for(String detailId : restIds){
                                String delSql = "delete from kq_DutyRestlength where id = ? ";
                                recordSet2.executeUpdate(delSql,detailId);
                              }
                            }
                          }
                          resultMap.put("sign", "-1");
                          resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                          return resultMap;
                        }
                      }
                    }
                  }
                }
                String paidLeaveEnableType_key = "paidLeaveEnableType"+changetype_index;
                String paidLeaveEnableType_value = Util.null2String(params.get(paidLeaveEnableType_key));

                String paidLeaveEnableTypeRule_key = "paidLeaveEnableTypeRule"+changetype_index;
                String paidLeaveEnableTypeRule_value = Util.null2String(params.get(paidLeaveEnableTypeRule_key));
                if("1".equalsIgnoreCase(paidLeaveEnableType_value)){
                  String paidLeaveEnableDefaultType_key = "paidLeaveEnableDefaultType"+changetype_index;
                  String paidLeaveEnableDefaultType_value = Util.null2String(params.get(paidLeaveEnableDefaultType_key));
                  if("2".equalsIgnoreCase(paidLeaveEnableDefaultType_value)){
                    String deleteSql = "delete from kq_DutyBalanceLengthDetail where rulesdetailid = ?";
                    flag = recordSet.executeUpdate(deleteSql, detailid);
                    if (!flag) {
                      resultMap.put("sign", "-1");
                      resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                      return resultMap;
                    }
//                  按加班时长范围设置转调休时长
                    JSONArray jsonArray = JSONArray.parseArray(paidLeaveEnableTypeRule_value);
                    for(int k = 0 ; k < jsonArray.size() ; k++){
                      JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                      String work = Util.null2String(jsonObject.get("work"));
                      String rest = Util.null2String(jsonObject.get("rest"));
                      String detailsql = "insert into kq_DutyBalanceLengthDetail(rulesdetailid,Dutylength,balancelength,dsporder) values(?,?,?,?)";
                      flag = recordSet.executeUpdate(detailsql, rulesdetailid, work, rest, k);
                      if (flag) {
                        int lengthDetailId = 0;
                        String getIdSql = "select max(id) maxId from kq_DutyBalanceLengthDetail";
                        recordSet1.executeQuery(getIdSql);
                        if (recordSet1.next()) {
                          lengthDetailId = recordSet1.getInt("maxId");
                          lengthDetailIds.add(""+lengthDetailId);
                        }
                        resultMap.put("sign", "1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                      } else {
                        if(!lengthDetailIds.isEmpty()){
                          if(lengthDetailIds != null && !lengthDetailIds.isEmpty()){
                            for(String detailId : lengthDetailIds){
                              String delSql = "delete from kq_DutyBalanceLengthDetail where id = ? ";
                              recordSet2.executeUpdate(delSql,detailId);
                            }
                          }
                        }
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                    }
                  }else if("3".equalsIgnoreCase(paidLeaveEnableDefaultType_value)){
                    String deleteSql = "delete from kq_DutyBalanceTimeDetail where rulesdetailid = ?";
                    flag = recordSet.executeUpdate(deleteSql, detailid);
                    if (!flag) {
                      resultMap.put("sign", "-1");
                      resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                      return resultMap;
                    }
//                  按加班的时间段设置转调休时长
                    JSONArray jsonArray = JSONArray.parseArray(paidLeaveEnableTypeRule_value);
                    for(int k = 0 ; k < jsonArray.size() ; k++){
                      JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                      String time = Util.null2String(jsonObject.get("time"));
                      String left = Util.null2String(jsonObject.get("left"));
                      String right = Util.null2String(jsonObject.get("right"));
                      String detailsql = "insert into kq_DutyBalanceTimeDetail(rulesdetailid,timepoint,lenOfDuty,lenOfLeave,dsporder) values(?,?,?,?,?)";
                      flag = recordSet.executeUpdate(detailsql, rulesdetailid, time, left, right,k);
                      if (flag) {
                        int timeDetailId = 0;
                        String getIdSql = "select max(id) maxId from kq_DutyBalanceTimeDetail";
                        recordSet1.executeQuery(getIdSql);
                        if (recordSet1.next()) {
                          timeDetailId = recordSet1.getInt("maxId");
                          timeDetailIds.add(""+timeDetailId);
                        }
                        resultMap.put("sign", "1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                      } else {
                        if(!timeDetailIds.isEmpty()){
                          if(timeDetailIds != null && !timeDetailIds.isEmpty()){
                            for(String detailId : timeDetailIds){
                              String delSql = "delete from kq_DutyBalanceTimeDetail where id = ? ";
                              recordSet2.executeUpdate(delSql,detailId);
                            }
                          }
                        }
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                    }
                  }
                }else if("2".equalsIgnoreCase(paidLeaveEnableType_value)){
                  String paidLeaveEnableFlowType_key = "paidLeaveEnableFlowType"+changetype_index;
                  String paidLeaveEnableFlowType_value = Util.null2String(params.get(paidLeaveEnableFlowType_key));
                  if("2".equalsIgnoreCase(paidLeaveEnableFlowType_value)){
                    String deleteSql = "delete from kq_DutyBalanceLengthDetail where rulesdetailid = ?";
                    flag = recordSet.executeUpdate(deleteSql, detailid);
                    if (!flag) {
                      resultMap.put("sign", "-1");
                      resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                      return resultMap;
                    }
//                  按加班时长范围设置转调休时长
                    JSONArray jsonArray = JSONArray.parseArray(paidLeaveEnableTypeRule_value);
                    for(int k = 0 ; k < jsonArray.size() ; k++){
                      JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                      String work = Util.null2String(jsonObject.get("work"));
                      String rest = Util.null2String(jsonObject.get("rest"));
                      String detailsql = "insert into kq_DutyBalanceLengthDetail(rulesdetailid,Dutylength,balancelength,dsporder) values(?,?,?,?)";
                      flag = recordSet.executeUpdate(detailsql, rulesdetailid, work, rest, k);
                      if (flag) {
                        int lengthDetailId = 0;
                        String getIdSql = "select max(id) maxId from kq_DutyBalanceLengthDetail";
                        recordSet1.executeQuery(getIdSql);
                        if (recordSet1.next()) {
                          lengthDetailId = recordSet1.getInt("maxId");
                          lengthDetailIds.add(""+lengthDetailId);
                        }
                        resultMap.put("sign", "1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                      } else {
                        if(!lengthDetailIds.isEmpty()){
                          if(lengthDetailIds != null && !lengthDetailIds.isEmpty()){
                            for(String detailId : lengthDetailIds){
                              String delSql = "delete from kq_DutyBalanceLengthDetail where id = ? ";
                              recordSet2.executeUpdate(delSql,detailId);
                            }
                          }
                        }
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                    }
                  }else if("3".equalsIgnoreCase(paidLeaveEnableFlowType_value)){
                    String deleteSql = "delete from kq_DutyBalanceTimeDetail where rulesdetailid = ?";
                    flag = recordSet.executeUpdate(deleteSql, detailid);
                    if (!flag) {
                      resultMap.put("sign", "-1");
                      resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                      return resultMap;
                    }
//                  按加班的时间段设置转调休时长
                    JSONArray jsonArray = JSONArray.parseArray(paidLeaveEnableTypeRule_value);
                    for(int k = 0 ; k < jsonArray.size() ; k++){
                      JSONObject jsonObject = (JSONObject) jsonArray.get(k);
                      String time = Util.null2String(jsonObject.get("time"));
                      String left = Util.null2String(jsonObject.get("left"));
                      String right = Util.null2String(jsonObject.get("right"));
                      String detailsql = "insert into kq_DutyBalanceTimeDetail(rulesdetailid,timepoint,lenOfDuty,lenOfLeave,dsporder) values(?,?,?,?,?)";
                      flag = recordSet.executeUpdate(detailsql, rulesdetailid, time, left, right,k);
                      if (flag) {
                        int timeDetailId = 0;
                        String getIdSql = "select max(id) maxId from kq_DutyBalanceTimeDetail";
                        recordSet1.executeQuery(getIdSql);
                        if (recordSet1.next()) {
                          timeDetailId = recordSet1.getInt("maxId");
                          timeDetailIds.add(""+timeDetailId);
                        }
                        resultMap.put("sign", "1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功
                      } else {
                        if(!timeDetailIds.isEmpty()){
                          if(timeDetailIds != null && !timeDetailIds.isEmpty()){
                            for(String detailId : timeDetailIds){
                              String delSql = "delete from kq_DutyBalanceTimeDetail where id = ? ";
                              recordSet2.executeUpdate(delSql,detailId);
                            }
                          }
                        }
                        resultMap.put("sign", "-1");
                        resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                        return resultMap;
                      }
                    }
                  }
                }
              }else{
                resultMap.put("sign", "-1");
                resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败
                return resultMap;
              }
            }

          }
          resultMap.put("sign", "1");
          resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功

        } catch (Exception e) {
            resultMap.put("sign", "-1");
            resultMap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
            writeLog(e);
        }
        return resultMap;
    }

}
